home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / MoveFile / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  7KB  |  290 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <dos/dos.h>
  4. #include <clib/exec_protos.h>
  5. #include <clib/dos_protos.h>
  6. #include <clib/alib_protos.h>
  7.  
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <ctype.h>
  12. #include <time.h>
  13.  
  14.  
  15. #ifdef __SASC
  16. int CXBRK(void) { return(0); }
  17. int _CXBRK(void) { return(0); }
  18. void chkabort(void) {}
  19. #endif
  20.  
  21. #include <HBBS/ANSI_Codes.h>
  22. #include <HBBS/Defines.h>
  23. #include <HBBS/types.h>
  24. #include <HBBS/structures.h>
  25. #include <HBBS/hbbscommon_protos.h>
  26. #include <HBBS/hbbscommon_pragmas.h>
  27. #include <HBBS/Hbbsnode_protos.h>
  28. #include <HBBS/Hbbsnode_pragmas.h>
  29. #include <HBBS/release.h>
  30. char *versionstr="$VER: MoveFile "RELEASE_STR;
  31.  
  32. struct Library *HBBSCommonBase=NULL;
  33. struct Library *HBBSNodeBase=NULL;
  34.  
  35. struct BBSGlobalData *BBSGlobal=NULL;
  36. struct NodeData *N_ND=NULL;
  37. int N_NodeNum=-1;
  38. char outstr[1024]; // temp string for displaying text..
  39.  
  40. long __stack=16384;
  41. // for global use..
  42.  
  43. int gargc;
  44. char **gargv;
  45.  
  46. static VOID cleanup(ULONG num)
  47. {
  48.   if (HBBSNodeBase)
  49.   {
  50.     HBBS_CleanUpDoor();
  51.     CloseLibrary (HBBSNodeBase);
  52.   }
  53.  
  54.   if (HBBSCommonBase)
  55.   {
  56.     HBBS_CleanUpCommon();
  57.     CloseLibrary (HBBSCommonBase);
  58.   }
  59.  
  60.   if (num) printf("Door Error = %d\n",num);
  61.  
  62.   exit(0);
  63. }
  64.  
  65. static VOID init(char *name)
  66. {
  67.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  68.   {
  69.     cleanup(1);
  70.   }
  71.  
  72.   if (!(HBBS_InitCommon()))
  73.   {
  74.     cleanup(2);
  75.   }
  76.  
  77.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  78.   {
  79.     cleanup(3);
  80.   }
  81.  
  82.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  83.   {
  84.     cleanup(4);
  85.   }
  86.   SetProgramName(name);
  87. }
  88.  
  89. void DoorMain( void )
  90. {
  91.   struct ConfData *Conf=NULL;
  92.   V_BIGNUM ConfNum;
  93.   struct List *PathList=NULL;
  94.   struct Node *node;
  95.   BOOL Done=FALSE,Error=FALSE;
  96.   struct InfoData ID;
  97.   BPTR FL;
  98.   struct FileInfoBlock FB;
  99.   BOOL UserAround=TRUE;
  100.   LONG nextparam=2;
  101.   char fromname[1024],toname[1024];
  102.   char dizfromname[1024],diztoname[1024];
  103.  
  104.   if (stricmp(gargv[2],"NOUSER")==0)
  105.   {
  106.     UserAround=FALSE;
  107.     nextparam=3;
  108.   } else DOOR_WriteText(ANSI_RESET);
  109.  
  110.   strcpy(fromname,N_ND->NodeSettings.NodePlayPen);
  111.   strcat(fromname,gargv[nextparam+1]); // nodePlaypen/<filename>
  112.  
  113.   if (FL=Lock(fromname,ACCESS_READ))
  114.   {
  115.     if (Examine(FL,&FB)) Done=TRUE;
  116.     UnLock(FL);
  117.   }
  118.  
  119.   if (Done)
  120.   {
  121.     Done=FALSE;
  122.  
  123.     if (stricmp("BAD",gargv[nextparam])==0)
  124.     {
  125.       if (Conf=FindConf())
  126.       {
  127.         PathList=Conf->BadFiles;
  128.       }
  129.       nextparam++;
  130.     }
  131.     else
  132.     {
  133.       if (stricmp("HOLD",gargv[nextparam])==0)
  134.       {
  135.         if (Conf=FindConf())
  136.         {
  137.           PathList=Conf->HoldFiles;
  138.         }
  139.         nextparam++;
  140.       }
  141.       else
  142.       {
  143.         if (stricmp("PARTUPLOAD",gargv[nextparam])==0)
  144.         {
  145.           if (Conf=FindConf())
  146.           {
  147.             PathList=Conf->PartUpload;
  148.           }
  149.           nextparam++;
  150.         }
  151.         else
  152.         {
  153.           if (sscanf(gargv[nextparam],"%ld",&ConfNum))
  154.           {
  155.             if (ValidConfNum(ConfNum-1))
  156.             {
  157.               Conf=(struct ConfData *)GetNode(BBSGlobal->ConfList,ConfNum-1);
  158.               PathList=Conf->Upload;
  159.             }
  160.             else
  161.             {
  162.               if (UserAround) DOOR_WriteText("Invalid Conference\r\n");
  163.             }
  164.             nextparam++;
  165.           }
  166.         }
  167.       }
  168.     }
  169.  
  170.     if (Conf && PathList)
  171.     {
  172.       for (node=PathList->lh_Head ; node->ln_Succ && !Error && !Done ; node=node->ln_Succ)
  173.       {
  174.         if (PathOK(node->ln_Name))
  175.         {
  176.  
  177.           if (FL=Lock(node->ln_Name,ACCESS_READ))
  178.           {
  179.             if (Info(FL,&ID))
  180.             {
  181.               if (ID.id_DiskState == ID_VALIDATED)
  182.               {
  183.                 if ( (ID.id_NumBlocks-ID.id_NumBlocksUsed) > (FB.fib_Size / ID.id_BytesPerBlock))
  184.                 {
  185.                   strcpy(toname,node->ln_Name);
  186.                   strcat(toname,gargv[nextparam]);
  187.                   nextparam++;
  188.                   if (!PathOK(toname)) // file exist in dest dir ?
  189.                   {
  190.  
  191.                     // try a rename first as it's tonnes quicker!
  192.                     if (!(Done=Rename(fromname,toname)))
  193.                     {
  194.                       // if that fails then copy it
  195.                       if (Done=HBBS_CopyFile(fromname,toname,32768))
  196.                       {
  197.                         // and if that worked, delete the first file..
  198.                         DeleteFile(fromname);
  199.                       }
  200.                     }
  201.                     if (Done)
  202.                     {
  203.                       if (stricmp(gargv[nextparam],"MOVEDIZ")==0)
  204.                       {
  205.                         nextparam++;
  206.                         strcpy(diztoname,node->ln_Name);
  207.                         strcat(diztoname,gargv[nextparam]);
  208.                         strcat(diztoname,".DIZ");
  209.  
  210.                         sprintf(dizfromname,"%sWork/%s.DIZ",N_ND->NodeLocation,gargv[nextparam]);
  211.  
  212.                         DOOR_SysopText("Copying DIZ to ");
  213.                         DOOR_SysopText(diztoname);
  214.                         DOOR_SysopText("\r\n");
  215.                         HBBS_CopyFile(dizfromname,diztoname,32768);
  216.                       }
  217.                       if (UserAround)
  218.                       {
  219.                         DOOR_WriteText("File Moved To ");
  220.                         DOOR_WriteText(toname);
  221.                         DOOR_WriteText("\r\n");
  222.                       }
  223.                     }
  224.                   }
  225.                   else Error=TRUE;
  226.                 }
  227.               }
  228.             }
  229.             UnLock(FL);
  230.           }
  231.         }
  232.       }
  233.     }
  234.     if (!Done || Error)
  235.     {
  236.       // could not put the file in a dir, move it to HBBS:LostFIles and record
  237.       // this in error log..
  238.  
  239.       sprintf(outstr,"Could Not Move %s to any Upload/BAD/HOLD Path!\nIt *MAY* now be in HBBS:LostFiles",gargv[3]);
  240.       HBBS_LogError(BBSGlobal->ErrorLogFile,ERR_GENERAL,outstr,TYPE_WARNING);
  241.       if (UserAround)
  242.       {
  243.         DOOR_WriteText("Could Not Move File, Trying To Move It To \"HBBS:LostFiles\"\r\n"
  244.                        "Check your upload paths are valid\r\n");
  245.       }
  246.       strcpy(toname,"HBBS:LostFiles/");
  247.       strcat(toname,gargv[3]);
  248.  
  249.       if (!(Done=Rename(fromname,toname)))
  250.       {
  251.         // if that files then copy it
  252.         if (Done=HBBS_CopyFile(fromname,toname,32768))
  253.         {
  254.           // and if that worked, delete the first file..
  255.           DeleteFile(fromname);
  256.         }
  257.       }
  258.  
  259.  
  260.       if (Done && UserAround)
  261.       {
  262.         DOOR_WriteText("Moved File To HBBS:LostFiles OK\r\n");
  263.       }
  264.     }
  265.   }
  266.   if (!Done && UserAround) DOOR_WriteText("Error Locating/Moving File!\r\n");
  267. }
  268.  
  269. int main(int argc,char **argv)
  270. {
  271.   gargc=argc;
  272.   gargv=argv;
  273.  
  274.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  275.   {
  276.     printf("Invalid/No Paramaters for door!\n");
  277.     exit (20);
  278.   }
  279.   init("MoveFile");
  280.  
  281.   if (BBSGlobal=HBBS_GimmeBBS())
  282.   {
  283.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  284.     {
  285.       DoorMain();
  286.     }
  287.   }
  288.   cleanup(0);
  289. }
  290.